package film

import (
	"errors"
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	FilmModel "jy_go/app/home/model/film"
	"jy_go/db"
	"strconv"
)


var (
	Db = db.GetDb()
)

//电影网址列表
func Lst(c *gin.Context){
	Limit, err := strconv.Atoi(c.DefaultPostForm("Limit", "10"))

	if err != nil{
		c.JSON(400,gin.H{"code":"error","message":"错误传参"})
		return
	}

	Page,err := strconv.Atoi(c.DefaultPostForm("Page", "1"))
	if err != nil{
		c.JSON(400,gin.H{"code":"error","message":"错误传参"})
		return
	}

	//初始化结构体
	var data = make([]FilmModel.Film, 0)
	var model FilmModel.Film
	if err := Db.Model(&model).Limit(Limit).Offset((Page - 1) * Limit).Find(&data).Error; err != nil && errors.Is(err,gorm.ErrRecordNotFound){
		c.JSON(200,gin.H{"code":"success","message":"暂无数据","data":data,"limit":Limit,"page":Page})
		return
	}
	c.JSON(200,gin.H{"code":"success","message":"查询成功","data":data,"limit":Limit,"page":Page})
	return
}












